package com.example.langchanin4jdemo1.controller;

import dev.langchain4j.community.model.dashscope.QwenChatModel;
import dev.langchain4j.data.message.UserMessage;
import dev.langchain4j.memory.ChatMemory;
import dev.langchain4j.memory.chat.MessageWindowChatMemory;
import dev.langchain4j.model.chat.ChatLanguageModel;

public class ChatMemoryTest {
    public static void main(String[] args) {
        ChatLanguageModel model = QwenChatModel.builder()
                .apiKey("sk-875dd6ef14244431acdc7ccb974f5bfe")
                .modelName("deepseek-r1")
                .build();
        ChatMemory chatMemory = MessageWindowChatMemory.builder()
                .maxMessages(10)
                .build();

        //消息存储到 chatMemory
        chatMemory.add(UserMessage.from("你好，我是小明，你是我的好兄弟，你叫小强"));

        String text1 = model.chat(chatMemory.messages()).aiMessage().text();
        System.out.println(text1);

        chatMemory.add(UserMessage.from("小明最好的朋友是谁"));
        String text2 = model.chat(chatMemory.messages()).aiMessage().text();
        System.out.println(text2);
    }
}
